import { scrollMixin } from "utils/mixin";
export default {
  components: {},
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      rankingList: [],
      isLoadMore: true,
      page: 1,
      total_page: 0,
      city:'',
      cityCode:'',
      latitude:'',
      longitude:''
    };
  },
  activated() {
    if(this.$route.query.localCity) {
      this.city = this.$route.query.localCity;
    } else {
      this.cityCode = this.$route.query.cityCode;
    }
    this.page = 1;
    this.latitude = this.$route.query.latitude;
    this.longitude = this.$route.query.longitude;
    this.getGoodsByShowSales();
  },
  methods: {
    getGoodsByShowSales() {
      $http.get("plugin.travel-around.frontend.index.index.getGoodsByShowSales", {city:this.city,cityCode:this.cityCode,basic_info:1}, "加载中..").then(response => {
        if (response.result == 1) {
          let basicInfo = response.basic_info;
          let res = response.data;
          this.rankingList = res.data;
          this.isLoadMore = true;
          this.total_page = res.last_page;
          if (!this.total_page) {
            this.page = 0;
          }
          this.$nextTick(() => {
            this.fun.wxShare(
              "",
              { mid: this.fun.getKeyByMid() },
              {
                url: window.location.href,
                title: '周边游排行榜',
                imgUrl: basicInfo?.home.mailInfo?.logo_url,
                description: '全国周边吃喝玩乐特惠套餐！'
              }
            );
          },50);
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        $http.post("plugin.travel-around.frontend.index.index.getGoodsByShowSales", { page: this.page }, "加载中").then(
          res => {
            this.isLoadMore = true;

            if (res.result === 1) {
              let myData = res.data.data;
              this.rankingList = [...this.rankingList, ...myData]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            // error callback
          }
        );
      }
    },
    rankingNavTo(id) {
      this.$router.push(this.fun.getUrl("tourAroundGoodsDetails", {}, { goodsId: id,longitude:this.longitude,latitude:this.latitude }));
    }
  }
};
